package edu.xmut.yuepai.upload.controller;


import edu.xmut.yuepai.common.result.R;
import edu.xmut.yuepai.model.vo.UploadVO;
import edu.xmut.yuepai.upload.service.UploadService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/upload")
public class UploadController {

    @Resource
    private UploadService uploadService;

    @PostMapping("/picture")
    public R uploadPicture(@RequestParam("file") MultipartFile multipartFile) {
        // 先判断图片是否为空
        boolean isEmpty = multipartFile.isEmpty();
        if (isEmpty) {
            return R.fail("上传的图片不能为空");
        }
        UploadVO uploadVO = uploadService.uploadBlogPicture(multipartFile);
        return R.ok(uploadVO);
    }
}
